package com.aku.controller.api;

import com.aku.service.StudentService;
import com.aku.vo.RegisterStudent;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/api/auth")
public class ApiAuthController {

    @Resource
    private StudentService studentService;

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public String register(@RequestParam("name")String name,
                           @RequestParam("sex")String sex,
                           @RequestParam("grade")String grade,
                           @RequestParam("username")String username,
                           @RequestParam("password")String password){
        RegisterStudent student = new RegisterStudent(name, sex, grade, username, password);
        boolean flag = studentService.insertStudent(student);
        if (flag){
            return "redirect:/page/auth/login";
        }
        return "redirect:/page/auth/register";
    }
}
